package com.tshopping.controller;

import com.tshopping.bean.Store;
import com.tshopping.service.GoodsService;
import com.tshopping.service.StoreService;
import com.tshopping.service.UserService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @name: AdministratorController
 * @description: 管理员页面控制器
 * @author: Jackeys
 * @date: 2021-02-01 14:29
 */
@RestController
@RequestMapping("/AdministratorController")
@CrossOrigin
public class AdministratorController {

    @Autowired
    private UserService userService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private StoreService storeService;

    @PostMapping(value = "/getAllUser")
    /**
     * @description 获取所有用户
     * @Param: currentPage
     * @return
     * @author Jackeys
     * @date 2021-02-01 14:32
     */
    public ResponseData getAllUser(int currentPage){
        return userService.getAllUser(currentPage);
    }

    @PostMapping(value = "userIsValid")
    /**
     * @description 账户封停
     * @Param: isValid
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 15:07
     */
    public ResponseData userIsValid(int isValid,int id){
        return userService.updateIsValid(isValid,id);
    }

    @PostMapping(value = "/deleteUser")
    /**
     * @description 删除用户
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 15:08
     */
    public ResponseData deleteUser(int id){
        return userService.deleteUser(id);
    }

    @PostMapping(value = "/deleteGoods")
    /**
     * @description 删除商品
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 15:39
     */
    public ResponseData deleteGoods(int id){
        return goodsService.deleteGoods(id);
    }

    @PostMapping(value = "/getAllGoods")
    /**
     * @description 获取所有商品
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 15:46
     */
    public ResponseData getAllGoods(int currentPage){
        return goodsService.getAllGoods(currentPage);
    }

    @PostMapping(value = "/approveGoods")
    /**
     * @description 审核商品
     * @Param: isApprove
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 15:46
     */
    public ResponseData approveGoods(int isApprove,int id){
        return goodsService.isApprove(isApprove,id);
    }

    @PostMapping(value = "/getAllStore")
    /**
     * @description 返回所有店铺
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 16:57
     */
    public ResponseData getAllStore(int currentPage){
        return storeService.getAllStore(currentPage);
    }

    @PostMapping(value = "/deleteStore")
    /**
     * @description 删除店铺
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 16:56
     */
    public ResponseData deleteStore(int id){
        return storeService.deleteStore(id);
    }

    @PostMapping(value = "/approveStore")
    /**
     * @description 审核店铺
     * @Param: isApprove
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 16:58
     */
    public ResponseData approveStore(int isApprove,int id){
        return storeService.approveStore(isApprove,id);
    }
}
